"""
删除用户
"""
import logging

import pytest
from Config.Base import Base
from playwright.sync_api import Page, expect, Playwright
from Config.config import *
from Config.URL import *
import allure, os
from Config.Base import Base
from Config.Tool import tool

# 测试用例数据
case_data = {'module':'部门管理','caseid':'新建部门','account':'zhangsan','username':'张三'}

@pytest.mark.基础管理系统
@pytest.mark.组织管理
@allure.step(case_data['caseid'])
#@pytest.mark.parametrize('case', case_data)
def test_case(playwright : Playwright) -> None:
    # 测试结果标题
    allure.dynamic.feature(case_data['module'])
    allure.dynamic.title(case_data['caseid'])
    allure.dynamic.suite(case_data['caseid'])

    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page

    page.wait_for_timeout(2000)

    page.goto(url + url_danweiguanli)

    page.locator("#app").get_by_text("环北部湾广西水资源配置有限公司").click()
    page.get_by_role("button", name=" 新建").click()
    page.get_by_placeholder("输入名称", exact=True).fill("部门测试001")
    page.get_by_placeholder("输入编码").fill("BMCS001")
    page.get_by_placeholder("选择部门主管").click()
    page.get_by_text(bd_zhihuigu).click()
    page.get_by_title("中国安能集团第一工程局有限公司").click()
    page.get_by_text("默认").click()
    page.get_by_text("陈凯").click()
    page.get_by_label("请选择用户").get_by_role("button", name="确 定").click()
    page.get_by_role("spinbutton").fill("1")
    page.get_by_placeholder("请输入", exact=True).fill("部门测试001备注")
    page.get_by_label("新建").get_by_role("button", name="确 定").click()

    # 断言
    expect(page.get_by_text('新建成功！')).to_be_visible()

    # 测试结果截图
    filename = os.path.join(test_screenshot_dir, f"{case_data['caseid']}.png")
    page.screenshot(path=filename)
    allure.attach.file(source=filename, name=case_data['caseid'],
                       attachment_type=allure.attachment_type.PNG)

    page.get_by_placeholder("请输入名称", exact=True).fill("001")
    page.get_by_role("button", name=" 查询").click()
    page.get_by_role("button", name="删除").first.click()
    page.get_by_role("button", name="确 定").click()

    # 断言
    expect(page.get_by_text('删除成功！')).to_be_visible()

    SetupTeardown.close()


